
### Figure 1###

year <- c(1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007)
new.linkages <- c(13,6,4,8,6,5,6,6,5,7,11,6,5,7,11,10,14,7,7,9,11,6,10,7,5,3,1)
countries.total <- c(50,52,53,55,55,53,53,52,51,49,44,44,44,43,42,43,46,44,46,45,46,47,44,38,40,36,33)

par(mar=c(5, 4, 4, 6) + 0.1)

plot(year, new.linkages, pch=16, axes=FALSE, ylim=c(0,15), xlab="", ylab="", 
     type="b",col="black")
axis(2, ylim=c(0.15),col="black",las=1)  ## las=1 makes horizontal labels
mtext("New PGM Linkages",side=2,line=2.5)
box()
par(new=TRUE)

plot(year, countries.total, pch=15,  xlab="", ylab="", ylim=c(30,60), 
     axes=FALSE, type="b", col="red")
mtext("Countries with PGM Linkages",side=4,col="red",line=4) 
axis(4, ylim=c(30,60), col="red",col.axis="red",las=1)

axis(1,pretty(range(year),5))
mtext("Year",side=1,col="black",line=2.5) 

legend("topleft",legend=c("New Linkages","Total Countries"),
       text.col=c("black","red"),pch=c(16,15),col=c("black","red"))


### Figure 2 ###

library(ggplot2)
Probs <- data.frame(YearsSinceCoup = c(0, 1 , 2, 3, 4, 5, 6, 7 ,8 , 9 , 10),
                    PredictedProbabilities = c(.0904854, .0645101,.0572296,.0540501,.0521398,.0508738,.050027,.0493819,.0488847, .0484906, .04817 ),
                    SE = c( .0227645, .0088194,.0059993 , .0051184, .0051184,.0045618, .0044771,  .0044315,  .0044075,  .0043953,   .0043897),
                    modelName = "Probability of PGM Linkage Formation")
Probs$YearsSinceCoup <- factor(Probs$YearsSinceCoup,c(0, 1,2,3,4,5,6,7,8,9,10))

interval2 <- -qnorm((1-0.95)/2) # 95% multiplier
limits <- aes(ymax = PredictedProbabilities + SE, ymin=PredictedProbabilities - SE)


ggplot() +
  geom_point(data = Probs, aes(x = YearsSinceCoup, y = PredictedProbabilities),
             colour = 'red', size = 3) +
  geom_pointrange(data = Probs, aes(x = YearsSinceCoup, y = PredictedProbabilities,
                                    ymin = PredictedProbabilities - SE*interval2, ymax = PredictedProbabilities + SE*interval2),
                  colour = 'red', width = 0.35)+theme_classic(base_size = 18)+ labs(x = "Years Since Coup", y = "Probability of PGM Linkage Formation")
